<?php

/**
 * ingreso actions.
 *
 * @package    cronos-doctrine
 * @subpackage ingreso
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ingresoActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->operadores_ingresos = Doctrine_Core::getTable('OperadoresIngreso')
      ->createQuery('a')
      ->execute();
  }
  
  
   public function executeCierreRuta(sfWebRequest $request)
  {
  
    $ingresoEfectivo           = $request->getParameter('ingreso_efectivo');
    $ingresoResto              = $request->getParameter('ingreso_resto');
    $nota                      = $request->getParameter('ingreso_nota');
    $ingreso_id                = $request->getParameter('ingreso_id');
    
    
    $ingresos_array            = $request->getParameter('ingresos_array');
    
    $ingresos_array            = explode(",",$ingresos_array);
    
    foreach ($ingresos_array as $ingresosop){
        if($ingresosop){
            
            if($request->getParameter('check'.$ingresosop)=='on'){
                    
                    $ingreso = Doctrine_Query::create()
                        ->set('oi.is_sobre_op', "'1'")
                        ->update('OperadoresIngreso oi')
                        ->where('oi.id=?',$ingresosop)
                        ->execute();
                    
            }
            
        }
        
    }
    
    $total = $request->getParameter('total');
    
    $ingreso = Doctrine_Query::create()
                        ->set('oe.monto_deposito', "'".$total."'")
                        ->set('oe.nota_operador', "'".$nota."'")
                        ->set('oe.efectivo', "'".$ingresoEfectivo."'")
                        ->update('OperadoresEgresos oe')
                        ->where('oe.id=?',$ingreso_id)
                        ->execute();
    
    $this->redirect('dashboard/index');
    
    
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new OperadoresIngresoForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new OperadoresIngresoForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($operadores_ingreso = Doctrine_Core::getTable('OperadoresIngreso')->find(array($request->getParameter('id'))), sprintf('Object operadores_ingreso does not exist (%s).', $request->getParameter('id')));
    $this->form = new OperadoresIngresoForm($operadores_ingreso);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($operadores_ingreso = Doctrine_Core::getTable('OperadoresIngreso')->find(array($request->getParameter('id'))), sprintf('Object operadores_ingreso does not exist (%s).', $request->getParameter('id')));
    $this->form = new OperadoresIngresoForm($operadores_ingreso);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($operadores_ingreso = Doctrine_Core::getTable('OperadoresIngreso')->find(array($request->getParameter('id'))), sprintf('Object operadores_ingreso does not exist (%s).', $request->getParameter('id')));
    $operadores_ingreso->delete();

    $this->redirect('ingreso/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $operadores_ingreso = $form->save();

      $this->redirect('ingreso/edit?id='.$operadores_ingreso->getId());
    }
  }
}
